<% cache [ "v1", current_user] do %>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%= favicon_link_tag %>
    <title>Scumblr</title>
    <%= stylesheet_link_tag    "application" %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= javascript_include_tag "vendor/modernizr" %>
    <%= csrf_meta_tags %>

  </head>
  <body>
    <!-- Header and Nav -->
    <nav class="top-bar" data-topbar data-options="is_hover: false">
      <ul class="title-area">
        <!-- Title Area -->
        <li class="name">
          <p>Scumblr</p>
        </li>
        <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
      </ul>
      <section class="top-bar-section">
        <!-- Left Nav Section -->
        <% if user_signed_in? %>
          <ul class="left">
            <li class="name <%= @menu_item == "dashboard" ? "active" : "" %>"><%= link_to "Dashboard", dashboard_results_path %></li>
            <li class="name <%= @menu_item == "results" ? "active" : "" %>"><%= link_to "Results", root_path  %></li>
            <li class="name <%= @menu_item == "tasks" ? "active" : "" %>"><%= link_to "Tasks", tasks_path  %></li>
            <li class="name <%= @menu_item == "system_metadata" ? "active" : "" %>"><%= link_to "System Metadata", system_metadata_path  %></li>
            <li class="name <%= @menu_item == "events" ? "active" : "" %>"><%= link_to "Events", events_path  %></li>
            <li class='has-dropdown not-click'><%= link_to "Result Filters", "#"  %>
              <ul class="dropdown">
                <li><%= link_to "Manage", saved_filters_path(saved_filter_type: "Result") %></li>
                <li><label>My Filters</label></li>
                <% if current_user.saved_filters.count == 0 %>
                  <li><%= link_to "You have no saved filters.", "#", :class=> "italic" %></li>
                <% else %>
                  <% current_user.saved_filters.where(saved_filter_type:"Result").each do |filter| %>
                    <li><%= link_to filter.name, search_results_path(:saved_filter_id=>filter.id) %></li>
                  <% end %>
                <% end %>
                <li><label>Public Filters</label></li>
                <% if current_user.added_saved_filters.where(saved_filter_type:"Result").count == 0 %>
                  <li><%= link_to "No public filters added.", "#", :class=> "italic" %></li>
                <% else %>
                  <% current_user.added_saved_filters.where(saved_filter_type:"Result").each do |filter| %>
                    <li><%= link_to filter.name, search_results_path(:saved_filter_id=>filter.id) %></li>
                  <% end %>
                <% end %>
              </ul>
            </li>
            <li class='has-dropdown not-click'><%= link_to "Event Filters", "#"  %>
              <ul class="dropdown">
                <li><%= link_to "Manage", saved_filters_path(saved_filter_type: "Event") %></li>
                <li><label>My Filters</label></li>
                <% if current_user.saved_filters.count == 0 %>
                  <li><%= link_to "You have no saved filters.", "#", :class=> "italic" %></li>
                <% else %>
                  <% current_user.saved_filters.where(saved_filter_type:"Event").each do |filter| %>
                    <li><%= link_to filter.name, search_events_path(:saved_filter_id=>filter.id) %></li>
                  <% end %>
                <% end %>
                <li><label>Public Filters</label></li>
                <% if current_user.added_saved_filters.where(saved_filter_type:"Event").count == 0 %>
                  <li><%= link_to "No public filters added.", "#", :class=> "italic" %></li>
                <% else %>
                  <% current_user.added_saved_filters.where(saved_filter_type:"Event").each do |filter| %>
                    <li><%= link_to filter.name, search_events_path(:saved_filter_id=>filter.id) %></li>
                  <% end %>
                <% end %>
              </ul>
            </li>
            <% if current_user.admin? %>
              <li class='has-dropdown not-click'><%= link_to "Admin", "#"  %>
                <ul class="dropdown">
                  <li><%= link_to "Statuses", statuses_path %></li>
                  <li><%= link_to "Flags", flags_path %></li>
                  <li><%= link_to "Workflows", workflowable.workflows_path %></li>
                  <li><%= link_to "Users", users_path %></li>
                </ul>
              </li>
            <% end %>

          </ul>
        <% end %>
        <!-- Right Nav Section -->
          <ul class="right">
            <li class="divider"></li>
            <% if user_signed_in? %>
              <li class="has-dropdown click">
                <a href="#" class="" >Tasks
                  <span id="task_count">&nbsp;</span></a>
                <ul class="dropdown" id="status_notifications" data-url="<%= events_tasks_path%>">
                </ul>
              </li>
              <li class="divider"></li>

              <% if current_user.thumbnail.present? %>
                <li class="thumbnail"><%= image_tag current_user.thumbnail %></li>
              <% end %>
              <li class='has-dropdown not-click'><%= link_to current_user.email.truncate(20), "#"  %>
                <ul class="dropdown">
                  <li><%= link_to "Profile", edit_user_path(current_user) %></li>
                  <li><%= link_to('Logout', destroy_user_session_path, :method => :delete) %></li>
                </ul>
              </li>


            <% else %>
              <li><%= link_to "Sign in", openid_connect_path %></li>
            <% end %>
          </ul>

      </section>
    </nav>
<% end # end of current user cached%>

    <!-- Main Page Content and Sidebar -->
    <%= content_for?(:content) ? yield(:content) : yield %>
    <!-- End Main Content -->
    <!-- End Main Content and Sidebar -->
    <!-- Footer -->

    <footer class="row">
      <div class="large-12 columns">
        <hr />
        <div class="row">
          <div class="large-12 centered columns">
            <p>SCUMBLR - NETFLIX OSS - 2016</p>
          </div>
        </div>
      </div>
    </footer>
  </body>
